package com.woniuxy.school.commons.web.exception;


import com.woniuxy.commons.core.exception.SchoolException;
import com.woniuxy.commons.core.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class SchoolExceptionHandler {
    //全局异常处理
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        e.printStackTrace();
        return Result.getResult().setMessage("服务器异常").setCode(500);
    }

    /**
     * 自定义异常处理
     * @param e
     * @return
     */
   @ExceptionHandler(SchoolException.class)
    public Result handleSchoolException(SchoolException e){
        return Result.getResult().setMessage(e.getMessage()).setCode(e.getCode());
   }
}
